#include "StdAfx.h"
#include "FunctionDriverLine.h"
#include "RegFunctionDriverHelper.h"
#include "../LineBuilder.h"

CFunctionDriverLine::CFunctionDriverLine()
{
}
CFunctionDriverLine::~CFunctionDriverLine()
{
}

const Standard_GUID& CFunctionDriverLine::GetID() {
	static Standard_GUID anID(LINE_TWO_CUID);
	return anID;
}


void CFunctionDriverLine::Validate(TFunction_Logbook& log) const
{
	// We validate the object label ( Label() ), all the arguments and the results of the object:
	log.SetValid(Label(), Standard_True);
}

Standard_Boolean CFunctionDriverLine::MustExecute(const TFunction_Logbook& log) const
{
	// If the object's label is modified:
	if (log.IsModified(Label())) return Standard_True; 

	// Cut (in our simple case) has two arguments: The original shape, and the tool shape.
	// They are on the child labels of the box's label:
	// So, OriginalNShape  - is attached to the first  child label
	//     ToolNShape - is attached to the second child label.
	// 
	// Let's check them:
	if(CLineInfo::IsModified(Label(), log))
		return Standard_True;

	// if there are no any modifications concerned the box,
	// it's not necessary to recompute (to call the method Execute()):
	return Standard_False;
}

Standard_Integer CFunctionDriverLine::Execute(TFunction_Logbook& log) const
{
	CLineInfo info;
	if(!info.GetFromLabel(Label()))
		return 1;

	TopoDS_Shape shape;
	CLineBuilder builder;
	if(!builder.Build(&info, shape))
		return 1;

	// Build a TNaming_NamedShape using built box
	TNaming_Builder B(Label());
	B.Generated(shape);
	// That's all:
	// If there are no any mistakes we return 0:
	return 0;
}

//////////////////////////////////////////////////////////////////////////
IMPLEMENT_FUNCTIONDRIVER_HANDLE(CFunctionDriverLine)

REGISTER_FUNCTIONDRIVER(CFunctionDriverLine)